/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Utils;

import samoloty.controler.Controler;
import samoloty.controler.DowPanelControler;
import samoloty.controler.FlightPanelControler;
import samoloty.controler.FuelPanelControler;
import samoloty.controler.HoldsPanelControler;
import samoloty.controler.InfoPanelControler;
import samoloty.controler.PaxPanelControler;

/**
 *
 * @author borysfan
 */
public class MainValidator {

    private static MainValidator instance = null;
    private Controler controler;

    public static MainValidator getInstance(Controler c) {
        if (instance == null) {
            instance = new MainValidator(c);
        }
        return instance;
    }

    public MainValidator(Controler controler) {
        this.controler = controler;
    }

    public void validate() {
        boolean resultMajor = checkMajor();
        boolean resultMinor = checkMinor();
        if (resultMinor && resultMajor) {
            setEnabled(true);
        } else {
            setEnabled(false);
        }
    }

    private void setEnabled(boolean value) {
        controler.getView().setPrintVisible(value);
        controler.getView().setSaveVisible(value);
    }

    // FLT NO., ORIG.APT, DEST.APT, DAY, PREPARED BY, BASIC WEIGHT, BASIC INDEX, TAKE-OFF FUEL, TRIP FUEL, TAXI FUEL
    private boolean checkMajor() {

        //validate FlighScreen
        FlightPanelControler flightControler = controler.getFlightControler();
        String vFlightNumber = flightControler.getVFlightNumber();
        if (vFlightNumber.equals("0") || vFlightNumber.equals("")) {
            return false;
        }
        String vOrigin = flightControler.getVOrigin();
        if (vOrigin.equals("0") || vOrigin.equals("")) {
            return false;
        }
        String vDestination = flightControler.getVDestination();
        if (vDestination.equals("0") || vDestination.equals("")) {
            return false;
        }
        String vPreparedBy = flightControler.getVPreparedBy();
        if (vPreparedBy.equals("0") || vPreparedBy.equals("")) {
            return false;
        }

        //validate DowPanel
        DowPanelControler dowPanelControler = controler.getDowPanelControler();
        String vbasicweight = dowPanelControler.get_vbasicweight();
        if (vbasicweight.equals("0") || vbasicweight.equals("")) {
            return false;
        }
        String vbasicindex = dowPanelControler.get_vbasicindex();
        if (vbasicindex.equals("0") || vbasicindex.equals("")) {
            return false;
        }
        //validate FuelPanel

        FuelPanelControler fuelPanelControler = controler.getFuelPanelControler();
        String vtof = fuelPanelControler.get_vtof();
        if (vtof.equals("0") || vtof.equals("")) {
            return false;
        }
        String vtf = fuelPanelControler.get_vtf();
        if (vtf.equals("0") || vtf.equals("")) {
            return false;
        }
        String vtxf = fuelPanelControler.get_vtxf();
        if (vtxf.equals("0") || vtxf.equals("")) {
            return false;
        }

        return true;
    }
//jeżeli którykolwiek warunek z okna FUEL, PAX, HOLDS lub PREVIEW jest spełniony (czerwony)

    private boolean checkMinor() {
        FuelPanelControler fuelPanelControler = controler.getFuelPanelControler();
        PaxPanelControler paxPanelControler = controler.getPaxPanelControler();
        HoldsPanelControler holdsPanelControler = controler.getHoldsPanelControler();
        InfoPanelControler infoPanelControler = controler.getInfoPanelControler();
        if (!fuelPanelControler.isValid()) {
            return false;
        }
        if (!paxPanelControler.isValid()) {
            return false;
        }
        if (!holdsPanelControler.isValid()) {
            return false;
        }
        if (!infoPanelControler.isValid()) {
            return false;
        }
        return true;
    }
}
